package yznu_Servlet_search;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Goods_Utils.Good;
import Order_Utils.Order;
import User_Utils.User;
import index_Model.Join;
import yznu_Bean_handle.goodsManager;
import yznu_Bean_handle.joinManager;
import yznu_Bean_handle.othersStoreOrder;
import yznu_Bean_handle.vipManager;
import yznu_Servlet_good.*;
import yznu_Bean_handle.mainStoreOrder;
import yznu_Bean_handle.otherStoreManager;
import yznu_utils.Store;
public class SearchSer extends HttpServlet {

	String status = "";
	String Msg = "";
	String pre = "";
	String tag = "";
	String text = "";
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		pre = request.getParameter("pre");

		if(pre.equals("setStock")){
			
			boolean f = new goodsManager().setStock();
			request.setAttribute("source", "修改");
			request.setAttribute("Msg", "一键设置成功");
			int currentPage=(Integer) request.getSession().getAttribute("currentPage");
			request.getSession().setAttribute("currentPage", currentPage);
			int countPage=new goodsManager().countPage();
			request.getSession().setAttribute("countPage", countPage);
			ArrayList<Good> goods = new goodsManager().selectAll(currentPage);

			request.setAttribute("goods", goods);
			RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/goods.jsp");
			dispatcher.forward(request, response);
		}else if(pre.equals("user")){

			tag = request.getParameter("SearchRow");
			text = new String(request.getParameter("Search").getBytes("iso-8859-1"),"utf-8");
			int currentPage=(Integer) request.getSession().getAttribute("currentPage");
			request.getSession().setAttribute("currentPage", currentPage);
			int countPage=new vipManager().countPage();
			request.getSession().setAttribute("countPage", countPage);
			ArrayList<User> users = new vipManager().search(currentPage,tag,text);
			request.setAttribute("users", users);
			RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/users.jsp");
			dispatcher.forward(request, response);
		}else if(pre.equals("store")){

			tag = request.getParameter("SearchRow");
			text = new String(request.getParameter("Search").getBytes("iso-8859-1"),"utf-8");
			int currentPage=(Integer) request.getSession().getAttribute("currentPage");
			request.getSession().setAttribute("currentPage", currentPage);
			int countPage=new otherStoreManager().countPage();
			request.getSession().setAttribute("countPage", countPage);
			ArrayList<Store> stores = new otherStoreManager().search(currentPage,tag,text);
			request.setAttribute("stores", stores);
			RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/stores.jsp");
			dispatcher.forward(request, response);
		}else if(pre.equals("join")){

			tag = request.getParameter("SearchRow");
			text = new String(request.getParameter("Search").getBytes("iso-8859-1"),"utf-8");
			int currentPage=(Integer) request.getSession().getAttribute("currentPage");
			request.getSession().setAttribute("currentPage", currentPage);
			int countPage=new joinManager().countPage();
			request.getSession().setAttribute("countPage", countPage);
			ArrayList<Join> joins = new joinManager().search(currentPage,tag,text);
			request.setAttribute("joins", joins);
			RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/joins.jsp");
			dispatcher.forward(request, response);
		}else if(pre.equals("main")){

			text = new String(request.getParameter("Search").getBytes("iso-8859-1"),"utf-8");
			int currentPage=(Integer) request.getSession().getAttribute("currentPage");
			request.getSession().setAttribute("currentPage", currentPage);
			ArrayList<Order> orders = new mainStoreOrder().search(text);
			request.setAttribute("orders", orders);
			RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/mainStoreOrder.jsp");
			dispatcher.forward(request, response);
		}else if(pre.equals("others")){

			text = new String(request.getParameter("Search").getBytes("iso-8859-1"),"utf-8");
			int currentPage=(Integer) request.getSession().getAttribute("currentPage");
			request.getSession().setAttribute("currentPage", currentPage);
			ArrayList<Order> orders = new othersStoreOrder().search(text);
			request.setAttribute("orders", orders);
			RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/othersStoreOrder.jsp");
			dispatcher.forward(request, response);
		}else if(pre.equals("good")){

			tag = request.getParameter("SearchRow");
			text = new String(request.getParameter("Search").getBytes("iso-8859-1"),"utf-8");
			int currentPage=(Integer) request.getSession().getAttribute("currentPage");
			request.getSession().setAttribute("currentPage", currentPage);
			int countPage=new goodsManager().countPage();
			request.getSession().setAttribute("countPage", countPage);
			ArrayList<Good> goods = new goodsManager().search(currentPage,tag,text);
			request.setAttribute("goods", goods);
			RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/goods.jsp");
			dispatcher.forward(request, response);
		}else if(pre.equals("gadd")){

			RequestDispatcher dispatcher=request.getRequestDispatcher("/Pages/goodAdd.jsp");
			dispatcher.forward(request, response);
		}

	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
